package com.shoppingmall.controller.backstage;

import com.shoppingmall.common.ServletResponse;
import com.shoppingmall.pojo.User;
import com.shoppingmall.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * Created by
 *
 * @author touni
 * @date 2019/3/26
 * @time 10:34
 */
@RestController
@RequestMapping("/manager/statistic")
public class ManagerStatisticController {

    /**
     * 存储用户的session的名称
     */
    @Value("${USER_SESSION}")
    private String userSessoin;


    @Autowired
    private StatisticService statisticService;


    /**
     * 统计用户数量  商品数量 订单数量
     * @param session
     * @return
     */
    @RequestMapping("/base_count")
    public ServletResponse baseCount(HttpSession session){
        User userFromSession = (User)session.getAttribute(userSessoin);
        if (null == userFromSession || 1 != userFromSession.getRole()){

            return ServletResponse.createByErrorMessage("用户未登录或者权限不足");
        }

        return statisticService.baseCount();




    }






}
